package com.qen.yanggao

import cn.hutool.db.Db
import cn.hutool.poi.excel.ExcelUtil
import kotlin.String

fun main() {
    val list = Db.use().query("select * from TABLES ")
    val rows = ArrayList<Table>()
    for (entity in list) {
        val tableName = entity.getStr("table_schema")
        if(tableList.contains(tableName)){
            rows.add(
                Table(
                    kuName = entity.getStr("table_schema"),
                    kuCode = "utf8mb4",
                    biaoName = entity.getStr("table_name"),
                    biaoCode = entity.getStr("table_collation"),
                )
            )
        }
    }
    outExcel(rows)
}

data class Table(
    val kuName: String = "",
    val kuCode: String = "",
    val biaoName: String = "",
    val biaoCode: String = "",
)


fun outExcel(rows: ArrayList<Table>) {
    val writer = ExcelUtil.getWriter("${OutPath}所有表的.xlsx")
    writer.addHeaderAlias("kuName", "数据库名称")
    writer.addHeaderAlias("kuCode", "数据库编码")
    writer.addHeaderAlias("biaoName", "数据表名称")
    writer.addHeaderAlias("biaoCode", "数据表编码")
    writer.write(rows, true)
    writer.close()
}